package com.thjk.bdf.preloan.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.thjk.bdf.preloan.web.enums.InvoiceEnum;
import com.thjk.bdf.service.MerchantInfoService;
import com.thjk.bdf.service.response.MerchantInfoRseponse;

/**
 * 系统准入和商户准入
 *
 * @author zg
 */
@Controller
public class MerchantController {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MerchantInfoService merchantInfoService;

	/**
	 * 
	 * @Description: 用款输入商户营业执照/社会统一信用码提交后校验发票流失准入
	 * @params:参宿说明
	 */
	@RequestMapping(value = "/checkFlow", method = RequestMethod.POST)
	public String checkFlow(Map<String, Object> model, HttpServletRequest request) {

		String licenseNo = request.getParameter("licenseNo"); // 营业执照

		try {
			MerchantInfoRseponse result = merchantInfoService.selectMrtInvoiceFlow(licenseNo);
			logger.info("返回发票流水数据："+result.toString());

			if (InvoiceEnum.Error_1003_1.getCode().equals(result.getCode())) {
				return "bdf/invociceMiss";
			}
			if (InvoiceEnum.Error_1003_2.getCode().equals(result.getCode())) {
				return "bdf/invocing";
			}
			if (!"000000".equals(result.getCode())) {
				model.put("code", result.getCode());
				model.put("message", result.getMessage());
				return "bdf/refuse";
			}
			model.put("licenseNo", licenseNo);
			model.put("merchantName", result.getMchtName());

			return "bdf/applyChannel";
		} catch (Exception e) {
			logger.error("" + e);
			return "common/error";

		}

	}

	/**
	 * 
	 * @Description: 页面跳转
	 * @params:参宿说明
	 */
	@RequestMapping(value = "/merchantInfo", method = RequestMethod.GET)
	public String merchantInfo(Map<String, Object> model, HttpServletRequest request) {

		return "bdf/merchantInfo";

	}

}
